package com.dayu.gulimall.controller;

import com.dayu.gulimall.service.MallSearchService;
import com.dayu.gulimall.vo.SearchParam;
import com.dayu.gulimall.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author dayu
 * @version 1.0
 * @email dayu007@foxmail.com
 * @date 2020/12/26 21:46
 * @description
 */
@Controller
public class ElasticSearchController {

    @Autowired
    private MallSearchService mallSearchService;

    @GetMapping("list.html")
    public String list(SearchParam searchParam, Model model, HttpServletRequest request){

        String queryString = request.getQueryString();
        searchParam.set_queryString(queryString);

        SearchResult result=mallSearchService.search(searchParam);
        model.addAttribute("result",result);
        return "list";
    }
}
